{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "用Python编写代码实现两个同心圆，每个圆表示不同的分类，假设外圆为正类，内圆为负类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATUAAAEuCAYAAADvDoVcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAWUElEQVR4nO3dX4hkaX3G8efX1TO6pZs19g5BDV3ljRiDF9IjGFF3SDQhhk2yeiGkwRCQTnoh7qULk1jdFy0LuTHBLNIGlKQ7wZANSEASER13VolLr0gwxItAppf8MYy7ms06grvTv1x09aSn+5yqc6reU+d93/P9wGG3q89Uv13nPU+//8455u4CgFwstV0AAAiJUAOQFUINQFYINQBZIdQAZIVQA5CV5Sbf/P777/fhcNjkjwDQQc8888z33f1S0fcaDbXhcKiDg4MmfwSADjKzw7Lv0f0EkBVCDUBWCDUAWSHUAGSFUAOQFUINQFYINQBZqRVqZrZkZp8xs6fM7LqZvbWpgiFvW1tbQfYBzqrbUntQUs/d3yXp45I+Eb5IyMG0QNre3p76HlX2IfhwVq1Qc/cvSNoYfzmU9HToAiF+VYKkSiCFQPDhrNpjau7+spl9VtInJT139vtmtmFmB2Z2cPPmzRBlRGRmDaytrS2ZmcxMku78/+nQqbLPosqLRLn7TJukn5H0H5LuK9tnbW3NkZbRaDR1n+NqU/xvJZ3bit6z7D1C/5wqP6vK74y4SDrwsmwq+0bhztKHJT06/v97JX1X0oWy/Qm19CwqSOYJtdDlrfJzEJeQofYqSU9IelLSdUm/Mml/Qi0u87TCQu9TpSyLKm+V96A1F5dgoVZ3I9TisqhW2Ml7LsKswdfE74zFmRRqdvz9Zly+fNm5n1o8zEzTjneVfba2tpKa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yiKeSz5Wy7PBX8QNK9p75+jQJV7i4zszdI+rKkv3T3P2+7PJO4++9IepOkq2Z237zvV/lpUk1x95EkjbscXzGz97n7T8ys8BF8bTkppySZ2a6Ou5y/MX5cYDROlzMR1yX9iaTHzOyNkl4aD0FgRmb2OklfkvSIu3+57fKUMbMPS3q9uz8m6Zak/x3/dy6tt9ROjCvyySP4rut47Cq6R/CZ2dskfUTSz+s4hK+Z2UMtFytZ7v4dSV8dH/N9SZstFykHj+q4C/8Hp1rt0Q3l6Hjs7+3j2eQv6jiE5+7es/gWQFaiaakBQAiEGoCsEGoAskKoAcgKoQYgK4QagKwQagCyQqgByMr/AUlNezREWr82AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import warnings\n",
    "import matplotlib\n",
    "warnings.filterwarnings('ignore')\n",
    "matplotlib.rcParams['font.family'] = 'Arial Unicode MS'\n",
    "x_list, y_list, type_list = [], [], []\n",
    "plt.figure(figsize=(5,5))\n",
    "for e in [(2,'o',False),(3,'+',True)]:\n",
    "    r, symbol, flag = e\n",
    "    x = np.linspace(-r,r,30)\n",
    "    y1 = np.sqrt(r**2-x**2)\n",
    "    y2 = -y1\n",
    "    x_list = x_list + x.tolist() + x.tolist()\n",
    "    y_list = y_list + y1.tolist() + y2.tolist()\n",
    "    type_list = type_list + [flag]*(2*len(x))\n",
    "    plt.plot(x,y1,symbol,x,y2,symbol,color='black')\n",
    "vdata = pd.DataFrame({'x': x_list, 'y': y_list, 'type': type_list})\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "查看vdata的前几行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.862069</td>\n",
       "      <td>0.729862</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.724138</td>\n",
       "      <td>1.013582</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.586207</td>\n",
       "      <td>1.218174</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-1.448276</td>\n",
       "      <td>1.379310</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          x         y   type\n",
       "0 -2.000000  0.000000  False\n",
       "1 -1.862069  0.729862  False\n",
       "2 -1.724138  1.013582  False\n",
       "3 -1.586207  1.218174  False\n",
       "4 -1.448276  1.379310  False"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vdata.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在尝试用逻辑回归算法建立分类模型，以正确地识别出这两类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[60,  0],\n",
       "       [60,  0]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model.logistic import LogisticRegression  \n",
    "from sklearn.metrics import confusion_matrix\n",
    "tm = LogisticRegression(solver='lbfgs') \n",
    "X,y = vdata.drop(columns=['type']),vdata.type\n",
    "tm.fit(X,y)\n",
    "y_pred = tm.predict(X)\n",
    "confusion_matrix(y, y_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对X和y分别构建最高3阶的特征，并基于新特征集，建立模型，并分析预测效果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[60,  0],\n",
       "       [ 0, 60]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置阶数为2和3阶\n",
    "for i in [2,3]:\n",
    "    vdata['x'+str(i)]=vdata.x**i\n",
    "    vdata['y'+str(i)]=vdata.y**i\n",
    "X,y = vdata.drop(columns=['type']),vdata.type\n",
    "tm.fit(X,y)\n",
    "y_pred = tm.predict(X)\n",
    "confusion_matrix(y, y_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "查看逻辑回归拟合的系数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.  , -0.  ,  1.73,  1.8 , -0.  ,  0.  ])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "coef = np.round(tm.coef_,2)[0]\n",
    "coef"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如结果所示，只有两个预测变量起着主要作用，可使用如下代码查看具体变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['x2', 'y2'], dtype='object')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.columns[np.where(coef > 0)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以x2为横轴，以y2为纵轴将新特征绘制在二维坐标平面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATIAAAEuCAYAAAAN0p4lAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAANQUlEQVR4nO3dUYhc1R3H8d8/XSh1TWp1JxCk60obK30KOIGCTc2DBmuQ9qUU6osPsuiTkJKY1kofRKoUhEKfFsUSWx+KglQUqtIGgkZk9kEJErQU9k3ciFUiNbb478NMZJjOzL137r177//c7weCu5nZmf+Q2Z/nnvmfc8zdBQCR7Wq6AAAoiyADEB5BBiA8ggxAeAQZgPAIMgDhLVX9gCsrK762tlb1wwLouM3NzQvu3pt2W+VBtra2psFgUPXDAug4M9uadRuXlgDCI8gAhEeQAQiPIAMQHkEGIDyCDEB4BBmA8CrvIyvitsdP670PPv3y+/17l/XKscPNFQQgpMZGZJMhJknvffCpbnv8dDMFAQirsSCbDLGsvweAWVo5R8aoDEARrQwyLjEBFNFYkO3fuzz3di4xAeTVWJC9cuxwZpgBQB5W9XFw/X7fi2zjs3byxVz3ozUD6DYz23T3/rTbGp8jyzsqY94MwCyNB1mRS0zmzQBM02hn/2WTl4x5LzcBQGrBiAwAymplkM261ORTTgDTtDLIps2b8aklgFlaMUc2zbzQYtcMAONaOSKbh10zAEwKF2TsmgFgUrgg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SMyACil0SAzs5Nm9troz/earKVqZrZkZn8wszNm9qaZ3Zn9U/GY2RVm9k8zu7HpWupgZsdH/4Zvmdk9TddTNTPbZWZPjn4Hz5rZgaZrWkSucy3rMHHM3Kqk5ySF/fh3irskXXT3Q2a2ImlT0gsN11SHhzU8xyE5ZnZQw1PEbpF0paQHmq2oFkck7XH3m83siKRHJB1tuKbCGgsyjR0zJ2lrNILZk9B5AM9Jen709RdNFlKX0S/61ZLebrqWmhyVdF7Df8dUg+xzSctmtkvDQ4bONVzPQpq8tMw8Zi4yd7/o7h+b2W5Jz0p6qOmaqmRmS5IelXS86VpqtE/SQUk/kXSvpD+amTVbUuXOSNqjYWBvSHqn2XIW02SQZR4zF52ZXSvpVUnPuPuppuup2AlJT7t725e1lPGZpJfc/ZK7v6vh/2xXGq6paickve7uN0g6IOnRiAdwNxlkSR8zZ2b7JL0s6UF3f6Lpempwu6S7zey0hr8Ap8wstUNNz0q6dTQhvk/Dy8vUgntZ0vujrz+U9LGkS82Vs5hG+8jM7CENw+wrko65+xuNFVMxM/udpJ9qOGS/7Ifu/u+GSqrNKMzudffzWfeNZDRv9JiG87mS9Et3/1uDJVXOzL4h6SlJ39Bwzvwxd/9Ls1UVR0MsgPBoiAUQHkEGIDyCDEB4BBmA8AgyAOERZADCI8gAhEeQAQjvf1FyjUrBahabAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(5,5))\n",
    "plt.plot(vdata.x2,vdata.y2,'o')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
